package com.moli.iov.task.jobhandler;

import com.moli.iov.real.service.IRealService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 实时服务同步在线状态（设置所有车辆为离线状态）
 * </p>
 *
 * @author: zql
 * @Date: 2019/4/11 18:12
 */
@Slf4j
@JobHander(value="vovRealSyncJobHandler")
@Component
public class IovRealSyncJobHandler  extends IJobHandler {

    @Reference(group = "${service.group}", check = false)
    private IRealService realService;

    @Override
    public ReturnT<String> execute(String... params) throws Exception {
        try {
            syncReal();
            return ReturnT.SUCCESS;
        }catch(Exception e){
            log.error("通知real 服务更改车辆在线状态 异常", e);
            return ReturnT.FAIL;
        }
    }

    /**
     * 通知real 服务更改车辆在线状态
     */
    public void syncReal(){
        log.info("通知real 服务更改车辆在线状态 开始");
        realService.deleteAllOnlineVins();
        log.info("通知real 服务更改车辆在线状态 结束");
    }


}
